package com.example.springboot1.controller;

import com.example.springboot1.Service.UserService;

import com.example.springboot1.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/User/{id}")
    public User getUserById(@PathVariable("id") Integer id) {
        System.out.println(id);
        return userService.getUserById(id);
    }
    @GetMapping("/insertUser")
    public int InsertUser(@RequestBody User user) {
        int i = userService.InsertUser(user);
        return i;
    }

    @GetMapping("/updateUser")
    public int updateCity(@RequestBody User user) {
        int i = userService.updateUser(user);
        return i;
    }

    @GetMapping("/deleteUser/{id}")
    public int deleteUser(@PathVariable("id") Integer id) {

        return userService.deleteUser(id);
    }

    //    分页查询
//    接口路径：/user/page?pageNum=1&pageSize=10
//    @RequestParam接收
//    limit第一个参数= （pageNum-1)+pageSize
    @GetMapping("/page/{pageNum}/{pageSize}")
    public List<User> findPage(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
        pageNum = (pageNum-1);
        return userService.selectPage(pageNum,pageSize);
    }

}
